<template>
  <div id="add">
    <van-field
      :label="label"
      :placeholder="placeholder"
      :type="type"
      :rule="rule"
      v-model="text"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      text: "",
    };
  },
  props: ["label", "placeholder", "type", "rule"],
  methods: {
      handlerulg(){
        //   console.log(this.rule)
        // 吧rule变为真正的正则
        const rue = new RegExp(this.rule)
        if(rue.test(this.text)){
            // console.log('正则效验成功')
            this.$emit('inputchange',this.text)
        }
      }
  },
//   监听事件
  watch:{
    text () {
      this.handlerulg()
    },
  },
};
</script>

<style scoped>
</style>